package com.suixuan.support.log;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

/**
 * 
 * 
 * Nanjing Zhou Su co.,Ltd
 * 
 * @Title: LogFactory.java
 * @Package: com.suixuan.log
 * @Description: 日志工具类
 * @Author: suixuan
 * @Date 2010-3-10 下午05:41:27
 * @Version V1.0
 * 
 */
public final class LogFactory {
	private LogFactory() {
	}

	private static Logger logger = LogManager.getLogger(LogFactory.class);

	private static LogFactory factory = new LogFactory();

	public static LogFactory getInstance(Class<?> clazz) {
		logger = LogManager.getLogger(clazz);

		return factory;
	}

	/**
	 * 记录日志
	 * 
	 * @param constant
	 *            日志级别
	 * @param message
	 *            日志信息
	 */
	public void logRecord(LogConstant constant, String message) {
		switch (constant) {
		case FATAL:
			logger.fatal(message);
			break;
		case ERROR:
			logger.error(message);
			break;
		case WARN:
			logger.warn(message);
			break;
		case INFO:
			logger.info(message);
			break;
		case DEBUG:
			logger.debug(message);
			break;
		case TRACE:
			logger.trace(message);
			break;
		default:
			break;
		}
	}

	/**
	 *记录日志
	 * 
	 * @param constant
	 *            日志级别
	 * @param message
	 *            日志信息
	 * @param throwable
	 *            异常
	 */
	public void logRecord(LogConstant constant, String message, Throwable throwable) {
		switch (constant) {
		case FATAL:
			logger.fatal(message, throwable);
			break;
		case ERROR:
			logger.error(message, throwable);
			break;
		case WARN:
			logger.warn(message, throwable);
			break;
		case INFO:
			logger.info(message, throwable);
			break;
		case DEBUG:
			logger.debug(message, throwable);
			break;
		case TRACE:
			logger.trace(message, throwable);
			break;
		default:
			break;
		}
	}

}
